package com.ruoyi.web.controller.asset;

import com.ruoyi.asset.domain.TbAssets;
import com.ruoyi.asset.service.ITbAssetsService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 物品管理-固定资产Controller
 *
 * @author ruoyi
 * @date 2025-01-24
 */
@RestController
@RequestMapping("/assets/assets")
public class TbAssetsController extends BaseController
{
    @Autowired
    private ITbAssetsService tbAssetsService;

    /**
     * 查询物品管理-固定资产列表
     */
    @PreAuthorize("@ss.hasPermi('assets:assets:list')")
    @GetMapping("/list")
    public TableDataInfo list(TbAssets tbAssets)
    {
        startPage();
        List<TbAssets> list = tbAssetsService.selectTbAssetsList(tbAssets);
        return getDataTable(list);
    }

    /**
     * 导出物品管理-固定资产列表
     */
    @PreAuthorize("@ss.hasPermi('assets:assets:export')")
    @Log(title = "物品管理-固定资产", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TbAssets tbAssets)
    {
        List<TbAssets> list = tbAssetsService.selectTbAssetsList(tbAssets);
        ExcelUtil<TbAssets> util = new ExcelUtil<TbAssets>(TbAssets.class);
        util.exportExcel(response, list, "物品管理-固定资产数据");
    }

    /**
     * 获取物品管理-固定资产详细信息
     */
    @PreAuthorize("@ss.hasPermi('assets:assets:query')")
    @GetMapping(value = "/{assetId}")
    public AjaxResult getInfo(@PathVariable("assetId") Long assetId)
    {
        return success(tbAssetsService.selectTbAssetsByAssetId(assetId));
    }

    /**
     * 获取物品管理-固定资产详细信息
     */
    @GetMapping(value = "/getQrCodeInfo")
    public AjaxResult getQrCodeInfo(@Param("assetNo") String assetNo)
    {
        return success(tbAssetsService.selectTbAssetsByAssetNo(assetNo));
    }

    /**
     * 新增物品管理-固定资产
     */
    @PreAuthorize("@ss.hasPermi('assets:assets:add')")
    @Log(title = "物品管理-固定资产", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TbAssets tbAssets)
    {
        return toAjax(tbAssetsService.insertTbAssets(tbAssets));
    }

    /**
     * 修改物品管理-固定资产
     */
    @PreAuthorize("@ss.hasPermi('assets:assets:edit')")
    @Log(title = "物品管理-固定资产", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbAssets tbAssets)
    {
        return toAjax(tbAssetsService.updateTbAssets(tbAssets));
    }

    /**
     * 删除物品管理-固定资产
     */
    @PreAuthorize("@ss.hasPermi('assets:assets:remove')")
    @Log(title = "物品管理-固定资产", businessType = BusinessType.DELETE)
	@DeleteMapping("/{assetIds}")
    public AjaxResult remove(@PathVariable Long[] assetIds)
    {
        return toAjax(tbAssetsService.deleteTbAssetsByAssetIds(assetIds));
    }
}
